package com.ytc.restcontroller;

import com.ytc.mapper.BookMapper;
import com.ytc.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class BookServiceImpl {

    @Autowired
    private BookMapper bookMapper;

    //zzm:查询作者书籍总字数
    @RequestMapping("querySwords")
    public Long querySwords(@RequestParam("uId") Integer uId){
        return bookMapper.querySwords(uId);
    }

    //柴晓颖：查询章节内容
    @RequestMapping("queryChapter")
    public List<Book> queryChapter(@RequestParam("bookid") Integer bookid){
        return bookMapper.queryChapter(bookid);
    }

    //柴晓颖：查询上一章章节名
    @RequestMapping("queryLastChaptername")
    public String queryLastChaptername(@RequestParam("bookid") Integer bookid){
        return bookMapper.queryLastChaptername(bookid);
    }

    //柴晓颖：新增章节内容
    @PostMapping("addChapter")
    public void addChapter(@RequestBody Book book){
        bookMapper.addChapter(book);
    }

    //柴晓颖：查找章节去修改内容
    @RequestMapping("queryChapterByChapterid")
    public Book queryChapterByChapterid(@RequestParam("bChapterid") Integer bChapterid) {
        return bookMapper.queryChapterByChapterid(bChapterid);
    }

    //柴晓颖：修改章节内容
    @PostMapping("updateChapter")
    public void updateChapter(@RequestBody Book book){
        bookMapper.updateChapter(book);
    }

    //柴晓颖：删除章节内容
    @RequestMapping("delChapter")
    public void delChapter(@RequestParam("bChapterid") Integer bChapterid){
        bookMapper.deleteByPrimaryKey(bChapterid);
    }

    //柴晓颖：预览章节内容
    @RequestMapping("preview")
    public Book preview(@RequestParam("bChapterid") Integer bChapterid){
        return bookMapper.preview(bChapterid);
    }


    /**
     * 张阔：查询总字数
     * @param blId
     * @return
     */
    @RequestMapping("querySumNum")
    public Long querySumNum(@RequestParam("blId") Integer blId){
        return bookMapper.querySumNum(blId);
    }

    /**
     * 张阔：查询章节
     * @param bcid
     * @param blId
     * @return
     */
    @RequestMapping("queryChapterById")
    public Book queryChapterById(@RequestParam("bcid") Integer bcid,@RequestParam("blId")  Integer blId){
        return bookMapper.queryChapterById(bcid,blId);
    }

    /**
     * 张阔：查询书籍更新日期
     * @param blId
     * @return
     */
    @RequestMapping("queryNewDate")
    public String queryNewDate(@RequestParam("blId")  Integer blId){
        return bookMapper.queryNewDate(blId);
    }

}
